using Database.Mappings;
using Database.NHibernateInterface;
using NHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using FluentNHibernate.Cfg;
using NHibernate.Tool.hbm2ddl;

namespace Database.Hibernate
{
    public class FluentInitializer : INHibernateInitializer
    {
        public Configuration GetConfiguration()
            {
            var cfg = Fluently.Configure()
                            .Database(MsSqlConfiguration.MsSql2005.ConnectionString(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
                                        .ShowSql())
                            .Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMapping>())
                            .ProxyFactoryFactory(typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory))
                            .ExposeConfiguration(c => c.SetProperty("current_session_context_class", "thread_static"))
                            .BuildConfiguration();

            /*var schemaExport = new SchemaExport(cfg);
            schemaExport.Create(false, true);*/

            return cfg;
        }

    }
}
